package com.stock;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class StockQuery {
	private SessionFactory sessionFactory;
	private Session session;

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public Session getCurrentSession() {
		if(session==null||!session.isOpen()){
			session = sessionFactory.openSession();
		}
		return session;
	}
	
	public List get(String sql,int size) {
		Session session =getCurrentSession();
		Query query = session.createQuery(sql);
		query.setMaxResults(size);
		return query.list();
	}
	
	public List get(String sql) {
		return get(sql,30);
	}
	
	public List getAll(String sql) {
		Session session =getCurrentSession();
		Query query = session.createQuery(sql);
		return query.list();
	}
}
